package cvo.chess.tests;

import java.util.List;

import junit.framework.Assert;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import cvo.chess.client.entities.chessboard.ChessboardCoordinate;
import cvo.chess.client.entities.chessboard.Tile;
import cvo.chess.client.entities.game.IChessboard;

public class ChessboardCoordinateTester_8x8 {

	// The mock chessboard we will be using in all our test
	IChessboard board;

	// Set up the mock before every tets. This makes sure that you have every
	// time a clean object.
	// In this particular case, this is redundant.
	// But when using mocking frameworks, you really should do this!
	@Before
	public void setUp() throws Exception {

		// We don't actually use the "real" chess board.
		// We won't depend on the real board for those test
		// We simply write an new 'Test Chessboard Anonymous Mock Class
		// Something' to
		// provide the result we want to use in our test. For more advanced
		// mocking
		// you should us mocking frameworks....
		this.board = new IChessboard() {

			@Override
			public int getWidth() {
				return 8;
			}

			@Override
			public Tile getTileAt(ChessboardCoordinate position) {
				// This function is not required used in those tests
				return null;
			}

			@Override
			public int getHeight() {
				return 8;
			}

			@Override
			public List<Tile> getAllTiles() {
				// This function is not required used in those tests
				return null;
			}
		};
	}

	@After
	public void tearDown() throws Exception {
		this.board = null;
	}

	/*
	 *  Test the 4 corners. 
	 */
	@Test
	public void testA1() {
		ChessboardCoordinate bc = new ChessboardCoordinate(board, "A1");
		TestGetters(bc, "A1", 0, 7, 56);
	}

	@Test
	public void testA8() {
		ChessboardCoordinate bc = new ChessboardCoordinate(board, "A8");
		TestGetters(bc, "A8", 0, 0, 0);
	}

	@Test
	public void testH1() {
		ChessboardCoordinate bc = new ChessboardCoordinate(board, "H1");
		TestGetters(bc, "H1", 7, 7, 63);
	}

	@Test
	public void testH8() {
		ChessboardCoordinate bc = new ChessboardCoordinate(board, "H8");
		TestGetters(bc, "H8", 7, 0, 7);
	}

	/*
	 * Test some random tile somewhere 
	 */
	@Test
	public void testC6() {
		ChessboardCoordinate bc = new ChessboardCoordinate(board, "C4");
		TestGetters(bc, "C4", 2, 4, 34);
	}
		
	//TODO: Add test for illegal values
	
	
	/**
	 * A helper method 
	 * 
	 * @param bc
	 * @param A1notation
	 * @param col
	 * @param row
	 * @param position
	 */
	private void TestGetters(ChessboardCoordinate bc, String A1notation,
			int col, int row, int position) {

		Assert.assertEquals("ChessboardCoordinate.getA1Notation()", A1notation,
				bc.getA1Notation());
		Assert.assertEquals("ChessboardCoordinate.getCol()", col, bc.getCol());
		Assert.assertEquals("ChessboardCoordinate.getRow()", row, bc.getRow());
		Assert.assertEquals("ChessboardCoordinate.getPosition()", position,
				bc.getNummericPosition());
	}
}
